﻿using System;

namespace BlamanticUI.Components;

/// <summary>
/// Represents a toast message that called by <see cref="IToastService"/> service.
/// </summary>
[CssClass("toast")]
internal class Toaster : BlazorComponentBase, IHasUIComponent
{
    /// <summary>
    /// Gets or sets the state.
    /// </summary>
    [CssClass] public State? State => Setting.State;
    /// <summary>
    /// Gets or sets the color.
    /// </summary>
    [CssClass] public Color? Color => Setting.Color;
    /// <summary>
    /// Gets or sets a value indicating whether adapted inverted background by parent component.
    /// </summary>
    /// <value>
    ///   <c>true</c> if adapted; otherwise, <c>false</c>.
    /// </value>
    [CssClass] public bool Inverted => Setting.Inverted;

    [Parameter] public ToastSetting Setting { get; set; }

    protected override void AddContent(RenderTreeBuilder builder, int sequence)
    {
        builder.CreateComponent<Icon>(1, attributes: new { Setting.IconClass },condition:!string.IsNullOrEmpty(Setting.IconClass));

        builder.CreateComponent<Content>(2, content =>
        {
            content.CreateElement(0, "div", Setting.Title, new { @class = "ui header" }, !string.IsNullOrWhiteSpace(Setting.Title));
            content.AddContent(10, Setting.Message);
        });
    }
}
